package com.dj.product.k2faas.common.enums;

import com.dj.product.k2faas.common.exception.K2Exception;

/**
 * Created by 丁建 on 2025/9/23 09:22
 *
 * @author 丁建
 */
public enum DBType {
    POSTGRESQL, MYSQL, ORACLE, SQLSERVER;

    public String getDriverName() {
        return switch (this) {
            case POSTGRESQL -> "org.postgresql.Driver";
            case MYSQL -> "com.mysql.cj.jdbc.Driver";
            case ORACLE -> "oracle.jdbc.OracleDriver";
            case SQLSERVER -> "com.microsoft.sqlserver.jdbc.SQLServerDriver";
            default -> throw new K2Exception("不支持的数据源类型：%s".formatted(this.name()));
        };
    }

    public String getConnectionInitSql() {
        String sql = "SELECT 1";
        if (this == ORACLE) {
            sql = "SELECT 1 FROM DUAL";
        }

        return sql;
    }
}
